//
//  104. 二叉树的最大深度.swift
//  Top600
//
//  Created by rjb on 2021/7/28.
//

import Foundation
class Solution104 {
    // 二叉树的最大深度
    func maxDepth(_ root: TreeNode?) -> Int {
        return depath(root)
    }
    func depath(_ root: TreeNode?) -> Int {
        guard let root = root else {
            return 0
        }
        let leftHeight = depath(root.left)
        let rightHeight = depath(root.right)
        return max(leftHeight, rightHeight) + 1
    }
    
    static func test() {
        let solution = Solution104()
        let node3 = TreeNode(3)
        let node9 = TreeNode(9)
        let node20 = TreeNode(20)
        let node15 = TreeNode(15)
        let node7 = TreeNode(7)
        
        node3.left = node9
        node3.right = node20
        node20.left = node15
        node20.right = node7
        let result = solution.maxDepth(node3)
        print(result)
    }
}
